package com.shameit.goodqrinfomanager.ui.activity.setting;


import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.shameit.goodqrinfomanager.BaseMVVMActivity;
import com.shameit.goodqrinfomanager.MyApplication;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class BaseicSettingViewModel extends BaseViewModel {

    String baseurl = SPUtils.getInstance().getString(MyApplication.BaseUrl, "http://47.96.71.26:8888");
    public ObservableField<String> ipaddress = new ObservableField<>(baseurl);

    public BaseicSettingViewModel(@NonNull Application application) {
        super(application);
    }

    public BaseicSettingViewModel(@NonNull Application application, BaseModel model) {
        super(application, model);
    }

    public BindingCommand saveIpAddress = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            String newip = ipaddress.get().toString();
            MyApplication.saveHttpMsg(newip);
            //SPUtils.getInstance().put(MyApplication.BaseUrl, newip);
            ToastUtils.showShort("保存成功,请重新启动");
        }
    });
}
